
// When you import this file, you import all the cocos2d classes
#import "cocos2d.h"
#import "MapManager.h"
#import "Enemy.h"
#import "Bullet.h"
#import "Tower.h"
#import "Parameter.h"
#import "Warrior.h"
#import "WarriorSkill.h"
#import "AnimationStore.h"
#import "UIDefine.h"
#import "CLoadingW.h"
#import "CDAudioManager.h"
#import "CocosDenshion.h"




@interface EnemyEnter : NSObject
{
	int _interval;
	int _type;
}

@property(nonatomic, assign)int interval;
@property(nonatomic, assign)int type;

+(id)EnemyEnterMake:(int) interval type:(int)type;

@end




// HelloWorld Layer
@interface Game : CCLayer
{
	//动画编辑器解析
	CAnimationStoreW *m_Editor;
	
	int		temp;
	
	//地图
	CCSprite* m_Map;
	
	//子弹数组
	NSMutableArray* m_Bullet;
	
	//攻击塔的数组
	NSMutableArray* m_TowerList;
	
	//战鼓数组
	NSMutableArray* m_PowerUpTower;
	
	//小兵数组
	NSMutableArray* m_EnemyList;
	
	//波次数据
	NSMutableArray* m_EnemyWave;
	
	int m_WaveNum;
	int m_IndexInWave;
	int m_WaveInterval;
	
	//波次显示
	CCLabel *m_WaveLabel;
	
	//经验
	int m_WarriorExp;
	
	//战功
	int m_Exploit;
	
	//金钱显示
	int m_Money;
	CCLabel* m_MoneyLabel;
	
	//放塔的图标
	//普通箭塔图标
	CCSprite* m_IconArrow;
	
	//毒刺塔图标
	CCSprite* m_IconPoison;
	
	//穿刺塔图标
	CCSprite* m_IconPuncture;
	
	//投石机图标
	CCSprite* m_IconMangonel;
	
	//战鼓台图标
	CCSprite* m_IconPowerUpTower;
	
	//暂停按钮
	CCMenuItem* m_IconPause;
	
	//加速按钮
	CCMenuItem* m_IconAccelerate;
	
	//按钮触碰区域
	CGRect m_RectIconArrow;
	CGRect m_RectIconPoison;
	CGRect m_RectIconPuncture;
	CGRect m_RectIconMangonel;
	CGRect m_RectIconPowerUpTower;
	
	//地图管理
	MapManager* m_MapManager;

	//操作参数
	//拆塔,升级的精灵
	CCSprite *m_SpriteSelect;
	Tower* m_SelectTower;
	
	//剩余关卡生命数
	int m_LifeLeft;
	CCLabel *m_LifeLable;
	
	//通用
	//触摸状态    0 没有操作    1 放塔操作    
	//触摸状态
	ETouchState m_TouchState;
	
	//留在屏幕上的触点数量
	int m_TouchPointCount;
	
	//
	int m_TouchStatus;
	
	//要放置的塔的类型
	int m_TowerType;
	
	//放塔操作参数
	//放塔的图标
	CCSprite *m_PutTowerIcon;
	
/*武将相关参数*/
	
	//武将
	Warrior *m_Warrior;
	
	CCSprite * __apertureSpr;
	
	Enemy *m_EnemySelected;
	
	//武将技能Icon
	CCSprite *m_IconSkill_1;
	CCSprite *m_IconSkill_2;
	CCSprite *m_IconSkill_3;
	CCSprite *m_IconSkill_4;

	
	
	//技能Icon触摸范围
	CGRect m_TouchRectSkill_1;
	CGRect m_TouchRectSkill_2;
	CGRect m_TouchRectSkill_3;
	CGRect m_TouchRectSkill_4;
	
	
	//选中的技能
	int m_SkillSelect;
	
	//技能释放的点
	CGPoint m_PutSkillPoint;
	
	//落雷技能数组
	NSMutableArray *m_LuoLeiEffect;
	
	//八卦技能数组
	NSMutableArray *m_BaGuaEffect;
	
	//偷取术技能数组
	NSMutableArray *m_TouQuEffect;
	
	//八卦阵法术效果精灵存储器
	NSMutableArray * __BaGuaOneAction;
	NSMutableArray * __BaGuaTwoAction;
	//落雷技法术效果精灵存储器
	NSMutableArray * __LuoLeiOneAction;
	NSMutableArray * __LuoLeiTwoAction;
	//投取术法术效果精灵存储器
	NSMutableArray * __TouquOneAction;
	NSMutableArray * __TouquTwoAction;
	
	
	
	
	
	
//箭塔的各种数据
	//箭塔的区域数据对应在图片资源上的区域
	CGRect m_TowerRectInResource[9];
	
////waver 2010/8/4	///
	//帧显示倍速
	int	AccelerateNum;	
	
	//当前是新建的第几个动画
	int	actionTag;
	
	//当前关羽的攻击种类
	int	__attackKind;
	
	int loadImageNum;//当前加载到第几张图片
	
	BOOL __bMoveWeaponIcon;//当前是否在选择移动武器
	
	//放武将技能的图标
	CCSprite * __fireSkill;
	BOOL __bFireSkillIcon;//地图上是否有释放技能ICON
	NSMutableArray * __skillFireArray;//正在发动的技能存储
	
	//英雄动画
	CActionSpriteW * __guanMoveSpr[4];
	CActionSpriteW * __guanHitSpr[4];
	CActionSpriteW * __guanWaitSpr[4];
	CActionSpriteW * __guanFashuSpr[4];
	
	NSMutableDictionary * __guanActionArray;
	
	//当前是否有地图点击
	BOOL	__b_touch;
	//点击地图存储点
	CGPoint __b_touchPoint;
	//玩家选择的发动技能,点击ICON后加入,技能发动后删除掉
	NSMutableArray * __touchSkillArray;
	//发动技能时点击的坐标
	NSMutableArray * __touchLocArray;
	
	
	CDLongAudioSource * pAudio;
	CDLongAudioSource * pAudioTwo[10];
	

	
	NSMutableData * pData;
	NSMutableData* p;
	
	NSMutableArray * __DeadEnemy;
	
	
}

@property(nonatomic, retain) Tower* selectTower;


// returns a Scene that contains the HelloWorld as the only child
+(id) scene;

//初始化地图
-(void) InitMap;

//初始化数据,包括敌兵,箭塔,波次等
-(void) InitGameData;

//初始化UI,包括触控图标等
-(void) InitUI;

//初始化武将
-(void) InitWarrior;


//增加敌兵
-(void)addEnemy:(int)type;

//添加塔
-(void)addTower:(int)type location:(Location *)loc;

//敌兵移动以及状态刷新,包括寻路,死亡逻辑,到达终点逻辑
-(void)MoveEnemy;

//塔数据刷新, 以及AI,锁定敌兵(已经不再使用,仅供参考)
-(void)TowerFire;

//改写后的塔的刷新,加入了塔的旋转
-(void)TowerUpdate;

//计算塔的攻击力提升数据,
-(float)AttackPowerUp:(Tower*)tower;

//通过点得出在哪个格子中
-(Location*)GetLocation:(CGPoint)point;

//得到格子中心点坐标
-(CGPoint)GetPos:(Location*)loc;

//读取波次数据
-(void)LoadWaveFile:(const char*) filename;

//坐标转换, 屏幕上转换到地图上
-(CGPoint)ConvertToMap:(CGPoint)point;

//读取波此文件
-(void)LoadWaveFile:(const char*) filename;

//波次更新
-(void)WaveUpdate;

//通过起点和终点计算方向
-(int)GetDirectionFromLocation:(Location*) loc1 toLocation:(Location*)loc2;


/*子弹相关的方法*/

//子弹数组作用逻辑,包括飞行,生效
-(void) BulletUpdate;

//圆碰撞,重要算法,游戏中最多的碰撞判断
-(BOOL) IsImpactCircle:(CGPoint)center1 range1:(float)range1 center2:(CGPoint)center2 range2:(float)range2; 

//范围伤害
-(void) AreaHurtAtPoint:(CGPoint)pos withRange:(int)range andAttack:(float)attack;

//穿刺伤害
-(void) LineHurtFromStart:(CGPoint)point1 toEnd:(CGPoint)point2 withAttack:(float)attack;

//计算点到直线的距离
-(float) DistanceLineWithPoints:(CGPoint)point1 point2:(CGPoint)point2 toPoint:(CGPoint)point3;












/*武将相关方法*/

//武将刷新
-(void) WarriorUpdate;

//寻找目标
-(id) WarriorFindTarget;

//武将移动
-(void) WarriorRun;

/*武将技*/

//触发技能
-(void) PutEffect:(int)type usePoint:(CGPoint)uPoint;

//技能效果刷新
-(void) EffectUpdate;

//八卦阵对小兵速度影响参数
-(void) BaGuaAction:(EffectBaGua *) bagua;

//偷取术
-(BOOL) IsMoneyUp:(Enemy *) enemy;



/*触碰操作处理方法*/


//默认状态下触控事件
-(void) TouchesBeganDefault:(CGPoint *)touches count:(int)counts;

-(void) TouchesMoveDefault:(CGPoint *)touches count:(int)counts;

-(void) TouchesEndDefault:(CGPoint *)touches count:(int)counts;


//敌兵选中状态下触控事件
-(void) TouchesBeganEnemySelect:(CGPoint *)touches count:(int)counts;

-(void) TouchesMoveEnemySelect:(CGPoint *)touches count:(int)counts;

-(void) TouchesEndEnemySelect:(CGPoint *)touches count:(int)counts;


//箭塔选中状态下触控事件
-(void) TouchesBeganTowerSelect:(CGPoint *)touches count:(int)counts;

-(void) TouchesMoveTowerSelect:(CGPoint *)touches count:(int)counts;


-(void) TouchesEndTowerSelect:(CGPoint *)touches count:(int)counts;


//地图选中下的触控事件
-(void) TouchesMoveMapSelect:(CGPoint *)touches count:(int)counts;


-(void) TouchesEndMapSelect:(CGPoint *)touches count:(int)counts;

//放塔操作的触控事件
-(void) TouchesMovePutTower:(CGPoint *)touches count:(int)counts;

-(void) TouchesEndPutTower:(CGPoint *)touches count:(int)counts;

-(void) TouchesBeganPutTower:(CGPoint *)touches count:(int)counts;

//释放技能的触控事件
-(void) TouchesMovePutSkill:(CGPoint *)touches count:(int)counts;

-(void) TouchesEndPutSkill:(CGPoint *)touches count:(int)counts;

//////////////////////////waver code form 2010/8/4
#pragma mark 动画编辑器初始化
//敌兵状态变化引起动画的切换,kind = 0,移动;Kind =1,死亡
-(void) EnemyMoveActionChange:(Enemy *) pEnemy EnemyKind:(int)Type state:(int)kind;

//初始化动画编辑器的编辑文件
-(void) InitCAnimationStore;

//获取敌兵在编辑器上的动画序列
-(int)	GetEnemyMoveActionIndex:(int) direction;

//获取动画解析对应的敌兵移动Tag
-(int)	GetMoveBinTag:(int)enemyType;
//获取死亡动画解析对应TAG
-(int) GetDeadBinTag:(int)enemyType;

#pragma mark 系统资源加载
//加载图片
-(void)LoadImage;

//每一个图片加载完后调用一次
-(void)LoadPictureOver;

//初始化各种精灵
-(void)InitSprite;

#pragma mark 武器塔ICON显示
//添加武器ICON
-(CCSprite*)AddWeaponIcon:(int)weaponName;

//武器ICON隐藏与显示,是否返回
-(void)WeaponIconMove:(BOOL)b_back;

//拖动武器ICON到地图
-(void)MoveWeaponIconMap:(int)weaponName IsEnable:(BOOL)bIs;

//获取塔名称
-(NSString*)WeaponPngName:(int)weaponName;

//获取塔坐标
-(CGPoint)WeaponTouchPoint:(int)weaponName;

//获取塔的价格
-(int)WeaponPrice:(int)weaponName;

//声音播放静音回调
-(void)MusicBack;

#pragma mark 关羽动作切换
///////////////////////////////////////////////////
//初始化关羽的各种动作
-(void)InitGuanyuAnimation;

//将动画编辑器编辑的关于移动动画加入英雄精灵
-(void)CreateGuanMove:(int)binName beginTag:(int)firstTag;

//英雄动画方位改变
-(void)ChangeWarrirDirection:(int)oldAction oldKind:(int)oldBegin actionKind:(int)kindBegin;

//关于跑动到停止
-(void)GuanRunStop:(int)oldDirect oldAction:(int)oldKind newAction:(int)newKind;

//判断关羽动画攻击是否结束
-(BOOL)IsGuanAttackOver:(int)attackKind;

//添加关羽脚底光圈
-(void)AddApertureGuanYu;

//获得关羽当前动作的对应动画序列起始位置
-(int)GuanAnimationIndex;


#pragma mark 玩家操作点击地图
//点击可移动地点
-(void)TouchMovePoint:(CGPoint)tPoint IsEnableMove:(BOOL)isAble;

/////////////////////////关羽攻击//////////////////////////////////////
#pragma mark 关羽攻击

//关羽攻击结束
-(void)GuanYuAttackOver;

//关羽攻击时根据小兵位置判断超向
-(void)ChangeGuanAttackDirect;

#pragma mark 关羽移动
//关羽移动后判断下一步移动方位和位置
-(BOOL)CheckGuanYuNextMove:(float)delta;

#pragma mark 关羽技能动画
//显示八卦阵
-(void)PlaySkill:(CGPoint)usePoint;

//关羽技能ICON隐藏,b_back:true从隐藏中回来
-(void)SkillIconMove:(BOOL)b_back;

//拖动技能到地图显示施法范围//IsEnable是否是可施法范围
-(void)AddSkillAreaMap:(BOOL)IsEnable;

//时间到停止对应的八卦阵
-(void)StopSkill;

//发动武将技能
-(void)PlayWarriorSkill:(CGPoint)usePoint;

//落雷的效果产生
-(void)LuoLeiEffect:(EffectLuoLei * )pluolei;
 
//关羽技能释放动画是否结束
-(BOOL)IsGuanDoSkillOver;

//武将技能点击后发动
-(void)WarriorSkillEffect;

//检测当前选择的技能是否可用
-(BOOL)IsSkillEnable;





//点击技能加入技能发动QUEUE
-(void)TouchSKillIcon:(Location*)loc;

//武将火墙术发动
-(void)HuoqiangFire;

@end

@interface GameScene : CCScene
{
	
}

@end